<template>
  <div class="searchExam">
    <div v-if="$store.state.teacherInfomation">
      <!-- currentPage: 1, // 当前页码
      pageSize: 5, // 每页的数据条数 -->
      <el-table
        :data="
          tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        height="500"
        border
        style="width: 100%"
      >
        <el-table-column prop="school" label="学校" width="180">
        </el-table-column>

        <el-table-column prop="faculty" label="院系" width="180">
        </el-table-column>

        <el-table-column prop="eid" label="试卷id" width="180">
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              @click="handleEdit(scope.$index, scope.row)"
              >查看试卷</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页器 -->
      <div class="block" style="margin-top: 15px">
        <el-pagination
          align="center"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[1, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.length"
        >
        </el-pagination>
      </div>
    </div>
    <div v-else>请前往个人中心完善信息 <router-link to="/teacherHome/teacherHomepage">点击前往</router-link> </div>
  </div>
</template>
<script>
import axios from "axios";
import { Message } from "element-ui";
export default {
  methods: {
    //当选择每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.currentPage = 1; //从第一页开始显示
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
    //查看试卷
    handleEdit(index, row) {
      // console.log(index, row)
      this.$router.push(`/teacherHome/looksearchExam/${row.eid}`);
    },
  },
  data() {
    return {
      tableData: [{ e_id: "", e_sj: "", eid: "" }], //设初始值
      currentPage: 1, // 当前页码
      total: 20, // 总条数
      pageSize: 5, // 每页的数据条数
    };
  },
  mounted() {
    //获取试卷信息
    axios
      .get("/v1/teachers/examsearch")
      .then((result) => {
        // console.log(result.data);
        if (result.data.status == 200) {
          this.tableData = result.data.data;
        } else {
          Message.error({
            showClose: true,
            message: "没有试卷信息",
            type: "error",
          });
        }
      })
      .catch((err) => {
        console.log(err);
      });
  },
};
</script>
<style lang="scss">
.searchExam {
  margin: 0 auto;
  margin-top: 50px;
}
</style>